<template>
  <div>
    用户列表
    <el-table :data="userList" stripe style="width: 100%">
      <el-table-column prop="id" label="ID" width="180" ></el-table-column>
      <el-table-column prop="username" label="用户名" width="180"></el-table-column>
      <el-table-column prop="email" label="邮箱"></el-table-column>
      <el-table-column prop="phone" label="电话"></el-table-column>
      <el-table-column prop="createTime" label="注册时间">
        <template slot-scope="scope">
          <p>{{scope.row.createTime | formatDate}}</p>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      background
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page.sync="currentPage3"
      :page-size="10"
      layout="prev, pager, next, jumper"
      :total="total"
    ></el-pagination>
  </div>
</template>

<script>
import { userList } from "@/request/http";
import { userPagination } from "@/request/http";
export default {
  name: "userList",
  data() {
    return {
      userList: [],
      currentPage3: 1,
      pageNum: 1,
      total:''
    };
  },
  filters: {
    formatDate: function(value) {
      let date = new Date(value);
      let y = date.getFullYear();
      let MM = date.getMonth() + 1;
      MM = MM < 10 ? "0" + MM : MM;
      let d = date.getDate();
      d = d < 10 ? "0" + d : d;
      let a=""
      let h = date.getHours();
      if(h<12){
          a="上午"
      }else if(h==12){
          a="中午"
      }else{
          a="晚上"
          h=h-12
      }
      h = h < 10 ? "0" + h : h;
      let m = date.getMinutes();
      m = m < 10 ? "0" + m : m;
      let s = date.getSeconds();
      s = s < 10 ? "0" + s : s;
      return y + "/" + MM + "/" + d + " " +a+ h + ":" + m + ":" + s;
    }
  },
  methods: {
    // es7语法
    async BeforMethod() {
      const res = await userList({
        pageNum: 1
      });
      this.userList = res.data.data.list;
      this.total=res.data.data.total
      console.log(this.userList);
     
    },
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
    },
    handleCurrentChange(val) {
        this.pageNum=val
      userPagination(this.pageNum).then(data => {
          console.log(data.data.data.list)
          this.userList=data.data.data.list
      }),
       console.log(`当前页: ${val}`);
    }
  },
  mounted() {
    this.BeforMethod();
  }
};
</script>

<style>
</style>